// pages/helpcenter/helpcenter.js
// var WxParse = require('../../../wxParse/wxParse.js');
var app = getApp();
Page({

  /**
	 * 页面的初始数据
	 */
  data: {
    customer_open:true,
    show1:false,
    dataget: [],
    title: [],
    msgarr: [],
    msg: '',
    showbox: false,
    service_QRcode:'',
    service_mobile:'',
  },

  /**
	 * 生命周期函数--监听页面加载
	 */
  onLoad: function(options) {
    this.init();
    this._getData();
  },

  /**
	 * 生命周期函数--监听页面初次渲染完成
	 */
  onReady: function() {

  },

  /**
	 * 生命周期函数--监听页面显示
	 */
  onShow: function() {

  },

  /**
	 * 生命周期函数--监听页面隐藏
	 */
  onHide: function() {

  },

  /**
	 * 生命周期函数--监听页面卸载
	 */
  onUnload: function() {

  },

  /**
	 * 页面相关事件处理函数--监听用户下拉动作
	 */
  onPullDownRefresh: function() {

  },

  /**
	 * 页面上拉触底事件的处理函数
	 */
  onReachBottom: function() {

  },

  /**
	 * 用户点击右上角分享
	 */
  onShareAppMessage: function() {

  },
  init(){
    this.setData({
      customer_open: true,
      show1: false,
      service_QRcode: '',
      service_mobile: '',
    });
  },
  callPhone(){
    wx.makePhoneCall({
      phoneNumber: this.data.service_mobile,

    });
  },
  showPop(){
    if (this.data.customer_open){
      this.setData({
        show1: true
      });
    }
  },
  closePop(){
    this.setData({
      show1: false
    });
  },
  _getData() {
    var that = this;
    let urlStr = app.getNetAddresss("plugin.help-center.api.content.info");
    app._getNetWork({
      url: urlStr,
      success: function(resdata) {
        var res = resdata.data;
        if (res.result == 1) {
          console.log(res.data.customer_service.customer_open);
          that.setData({
            dataget: res.data.set_data,
            customer_open: res.data.customer_service.customer_open=='1'?true:false,
            cservice:res.data.customer_service.cservice,
            service_QRcode: res.data.customer_service.service_QRcode,
            service_mobile: res.data.customer_service.service_mobile,
          });
          let msgarr = that.data.msgarr;
          let title = that.data.title;
          that.data.dataget.map(response => {
            title.push(response.title);
            msgarr.push(response.content);
          });
          that.setData({
            title: title,
            msgarr: msgarr,
            msg: msgarr[0]
          });
        } else {
          wx.showToast({
            icon: 'none',
            title: res.msg,
            duration: 1500
          });
        }
      }
    });
  },
  showTap(e) {
    let index = e.currentTarget.dataset.index;
    console.log(e)
    this.setData({
      msginfo: this.data.msgarr[index],
      showbox: true
    });
    console.log(this.data.msgarr,index)
  },
  msgboxclose() {
    this.setData({
      showbox: false,
      msg: ''
    });
  }
});
